//
//  TransferOfOrderViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/29.
//

import UIKit
import SnapKit
import RxSwift

struct RepairCategory {
  let icon: UIImage
  let name: String
  let contain: String
}
let d = R.image.icon_dq
extension RepairCategory {
  static let items: [RepairCategory] = [
    .init(icon: R.image.icon_dq()!, name: "电器", contain: "包含：空调、电表箱、洗衣机、电视、微波炉、电磁炉"),
    .init(icon: R.image.icon_jj()!, name: "家居", contain: "包含：桌子、椅子、xxxxxx、xxxxx、桌子、椅子、xxxxxx、xxxxx、xxxxx、xxxxx/xxxx、xxxx"),
    .init(icon: R.image.icon_qt()!, name: "X报修项", contain: "包含：xxxxxx、xxxxx、xxxxx、xxxx/xxxxx、xxxx"),

  ]
}

class TransferOfOrderViewController: UIViewController {

  var datasource: [RepairCategory] = RepairCategory.items

  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    setupTreeView()
  }

  private lazy var tableView: UITableView = {
    let tb = UITableView(frame: .zero, style: .plain)
    tb.delegate = self
    tb.dataSource = self
    tb.separatorStyle = .none
    tb.register(UINib(resource: R.nib.repairItemsCell), forCellReuseIdentifier: "id")
    tb.tableFooterView = UIView()
    return tb
  }()
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension TransferOfOrderViewController {

  func setupTreeView() {

    title = "已转单"

    opacityNavigationBar(color: .white)

    view.backgroundColor = .designKit.background

    view.addSubview(tableView)
    tableView.snp.makeConstraints { make in
      make.top.equalTo(view.safeAreaLayoutGuide.snp.top).offset(8)
      make.left.right.equalToSuperview()
      make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
    }
  }
}

extension TransferOfOrderViewController: UITableViewDelegate, UITableViewDataSource {

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return datasource.count
  }

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "id", for: indexPath)
    if let item = cell as? RepairItemsCell  {
      item.iconImageView.image = datasource[indexPath.row].icon
      item.titleLabel.text = datasource[indexPath.row].name
      item.containLabel.text = datasource[indexPath.row].contain
    }
    return cell
  }

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    
    navigationController?.pushViewController(FillRepairInfomationViewController(), animated: true)
  }
}
